<?php defined('SYSPATH') or die('No direct script access.') ;
/**
 * 表格列表自动排序助手
 *
 * @author  Yellow.Chow <aultoale@gmail.com>
 * @version $Id: autosort.php 213 2012-05-24 09:33:22Z yellow.chow $
 * @license http://www.gnu.org/licenses/gpl-3.0.html    GPL 3
 */
class Helper_Autosort extends Helper
{

    /**
     * @var string
     */
    protected $_field = NULL;

    /**
     * @var string
     */
    protected $_direct = 'asc';

    /**
     * 构造方法
     */
    public function __construct($field, $direct)
    {
        View::set_global('autosort', $this);

        $this->_field  = Arr::get($_GET, 'field', $field);
        $this->_direct = strtolower(Arr::get($_GET, 'direct', $direct));
        $this->_direct != 'asc' AND $this->_direct = 'desc';
    }

    /**
     * 魔术方法，调用 get() 方法
     *
     * @param  string  $name
     * @return string
     */
    public function __get($name)
    {
        switch (strtolower($name))
        {
            // 排序字段
            case 'field' :
                return $this->_field;

            // 排序方向
            case 'direct' :
                return $this->_direct;
        }

        return NULL;
    }

}